<?php

namespace app\controller;

use app\BaseController;
use app\common\model\Product;
use app\common\model\ProductType;
use think\facade\View;

class Cases extends BaseController
{
    public function index()
    {
        $selected_id = $this->request->param('type_id', 0);
        //案例类型
        $case_type = ProductType::field('id,title')->where(['status' => 1])->select()->toArray();
        array_unshift($case_type, ['id' => 0, 'title' => '全部']);
        View::assign('case_type', $case_type);
        View::assign('selected_id', $selected_id);

        $cases_header_bg_img = get_sys_config('cases_header_bg_img');
        View::assign('cases_header_bg_img', $cases_header_bg_img);
        return View::fetch();
    }


    //页面渲染接口
    public function getlist(): void
    {
        $id = $this->request->param('type_id', 0);
        $limit = $this->request->param('limit',6);
        $page = $this->request->param('page',1);
        $where = [];
        if (intval($id) > 0) {
            $where = ['nav_id' => $id];
        }
        $total = Product::where($where)->where('status',1)->count();
        $res = Product::where($where)->where('status',1)->page($page,$limit)->select()->toArray();
        $data = [
            'info' => $res,
            'current_page' => $page,
            'has_more' => ($page * $limit) < $total
        ];
        $this->success('ok', $data);
    }
}
